#include <iostream>
#include "geometry.h"

int main()
{
   int n = 0, m = 0, k = 0;
   Point p;
   Polygon hull;
   std :: cin >> p;
   std :: cin >> n;
   for(int i = 0; i < n; i++)
   {
      Point x;
      std :: cin >> x;
      hull.add_point(x);
   }

   Polygon_with_holes polygon(hull);
   std :: cin >> m;
   for(int i = 0; i < m; i++)
   {
      Polygon hole;
      int hole_size = 0;
      std :: cin >> hole_size;
      for(int j = 0; j < hole_size; j++)
      {
         Point x;
         std :: cin >> x;
         hole.add_point(x);
      }
      polygon.add_hole(hole);
   }

   std :: cin >> k;
   res = new int [k];
   for (int i = 0; i < k; i++)
   {
      std :: cin >> p;
      std :: cout << polygon.contains(p) << "\n";
   }

   return 0;

}